import { debounce } from "@/utils/utilsList";
export default {
  data() {
    return {
      tableHeight: 530, //当前table高度
      clientHeight: document.documentElement.clientHeight,
      otherHeight: 200,
    };
  },
  created() {
    //  初始值，自己定义

    setTimeout(() => {
      this.tableHeight =
        this.clientHeight -
        this.otherHeight -
        document.getElementById("from-searchbar").clientHeight;
    }, 200);
  },
  watch: {
    //  监听高度变化
    clientHeight(newValue, oldValue) {
      if (newValue) {
        this.getTableHeight();
      }
    },
  },
  computed: {
    fromSearchbarH() {
      if (!document.getElementById("from-searchbar")) return 0;
      return document.getElementById("from-searchbar").clientHeight;
    },
  },
  mounted() {
    //  重置浏览器高度
    window.onresize = () => {
      this.clientHeight = document.documentElement.clientHeight;
    };
  },
  beforeDestroy() {
    window.onresize = null;
  },
  methods: {
    // 防抖
    getTableHeight: debounce(function () {
      // 给table高度赋值
      this.tableHeight =
        this.clientHeight -
        this.otherHeight -
        document.getElementById("from-searchbar").clientHeight;
    }, 300),
  },
};
